Imports System.Net
Imports System.IO

Partial Public Class LatestForumTopics
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim in2 As Integer
            Dim url As String = "http://tenisliga.forumotion.com/tenis-liga-glavno-da-se-igra-f1/"
            Dim HttpWReq As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
            Dim HttpWResp As HttpWebResponse = DirectCast(HttpWReq.GetResponse(), HttpWebResponse)
            Dim strmReader As New StreamReader(HttpWResp.GetResponseStream())
            Dim cachedHTML As String = strmReader.ReadToEnd()

            Dim sStart, sEnd As Integer
            Dim latestTopic As String

            sStart = cachedHTML.IndexOf("Latest topics") - 16 + 41
            sEnd = cachedHTML.IndexOf("div_marquee") + 26
            'sEnd = cachedHTML.IndexOf("'genmed'") + 26


            latestTopic = cachedHTML.Substring(sStart, sEnd - sStart)
            latestTopic = latestTopic.Replace("onmouseover=""document.getElementById('comments_scroll_container').stop();"" onmouseout=""document.getElementById('comments_scroll_container').start();""", "")
            latestTopic = latestTopic.Replace("href=""/tenis-liga-glavno-da-se-igra-f1", "href=""http://tenisliga.forumotion.com/tenis-liga-glavno-da-se-igra-f1")
            latestTopic = latestTopic.Replace("href=""/profile.forum", "href=""http://tenisliga.forumotion.com/profile.forum")
            'latestTopic = "<link rel=""stylesheet"" href=""http://tenisliga.forumotion.com/1-ltr.css"" type=""text/css"" /> " + latestTopic

            latestTopic = "<link type='text/css' rel='stylesheet' href='http://www.blogger.com/static/v1/widgets/2446921439-widget_css_bundle.css' /> <link rel=""stylesheet"" type=""text/css"" href=""http://www.blogger.com/static/v1/v-css/3727950723-blog_controls.css""/> <link rel=""stylesheet"" type=""text/css"" href=""http://www.blogger.com/dyn-css/authorization.css?targetBlogID=4225192462130314718&zx=81ecf546-929a-48f1-af40-7f21bbc47969""/> " + latestTopic

            'Response.Write(latestTopic)
            'Label1.Text = latestTopic


            Dim starts(4) As Integer
            Dim ends(4) As Integer
            Dim links(4) As String

            starts(0) = latestTopic.IndexOf("<a")
            ends(0) = latestTopic.IndexOf("</a>") + 4
            links(0) = latestTopic.Substring(starts(0), ends(0) - starts(0))

            starts(1) = latestTopic.IndexOf("<a", starts(0) + 2)
            ends(1) = latestTopic.IndexOf("</a>", ends(0) + 2) + 4
            links(1) = latestTopic.Substring(starts(1), ends(1) - starts(1))
            starts(1) = latestTopic.IndexOf("<a", starts(1) + 2)
            ends(1) = latestTopic.IndexOf("</a>", ends(1) + 2) + 4
            links(1) = latestTopic.Substring(starts(1), ends(1) - starts(1))

            starts(2) = latestTopic.IndexOf("<a", starts(1) + 2)
            ends(2) = latestTopic.IndexOf("</a>", ends(1) + 2) + 4
            links(2) = latestTopic.Substring(starts(2), ends(2) - starts(2))
            starts(2) = latestTopic.IndexOf("<a", starts(2) + 2)
            ends(2) = latestTopic.IndexOf("</a>", ends(2) + 2) + 4
            links(2) = latestTopic.Substring(starts(2), ends(2) - starts(2))

            starts(3) = latestTopic.IndexOf("<a", starts(2) + 2)
            ends(3) = latestTopic.IndexOf("</a>", ends(2) + 2) + 4
            links(3) = latestTopic.Substring(starts(3), ends(3) - starts(3))
            starts(3) = latestTopic.IndexOf("<a", starts(3) + 2)
            ends(3) = latestTopic.IndexOf("</a>", ends(3) + 2) + 4
            links(3) = latestTopic.Substring(starts(3), ends(3) - starts(3))

            starts(4) = latestTopic.IndexOf("<a", starts(3) + 2)
            ends(4) = latestTopic.IndexOf("</a>", ends(3) + 2) + 4
            links(4) = latestTopic.Substring(starts(4), ends(4) - starts(4))
            starts(4) = latestTopic.IndexOf("<a", starts(4) + 2)
            ends(4) = latestTopic.IndexOf("</a>", ends(4) + 2) + 4
            links(4) = latestTopic.Substring(starts(4), ends(4) - starts(4))


            For i As Integer = 0 To links.Length - 1
                links(i) = links(i).Replace("<a", "<a class=""topictitle"" target=_blank ")
            Next

            Dim list As String = "<ul>"
            For i As Integer = 0 To links.Length - 1
                If (links(i).IndexOf("company-of-heroes") < 0) Then
                    'links(i) = "<tr><td>" + links(i) + "</td></tr>" + Environment.NewLine
                    links(i) = "<li>" + links(i) + "</li>" + Environment.NewLine
                    list += links(i)
                End If
            Next
            list += "</ul>"

            Label1.Text = list

            'Response.Write(DateTime.Now.ToString())
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub

End Class